//
//  CDRefreshView.swift
//  demo01
//
//  Created by Mac on 16/10/9.
//  Copyright © 2016年 chendong. All rights reserved.
//

import UIKit

class CDRefreshView: UIView {

    //定义一个枚举属性来区别做什么事情
    //didSet 没法索引，类似于OC里面的getter方法
    var refreshState:CDRefreshState = .nomol {
        didSet{
            switch refreshState {
            case .nomol:
                titlel.text = "恩，再用点力"
                UIView.animate(withDuration: 0.25, animations: {
                    self.arrowView.transform = CGAffineTransform.identity
                    self.arrowView.isHidden = false
                    self.activityview.stopAnimating()
                })
                
            case .pulling:
                titlel.text = "放手就刷新数据"
                UIView.animate(withDuration: 0.25, animations: {
                    self.arrowView.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI) - 0.001)
                })
            case .willRefresh:
                titlel.text = "正在刷新数据"
                arrowView.isHidden = true
                activityview.startAnimating()
            }
        }
    }
    
    @IBOutlet weak var arrowView: UIImageView!
    
    @IBOutlet weak var activityview: UIActivityIndicatorView!
    
    @IBOutlet weak var titlel: UILabel!
    
    class func refreshV() -> CDRefreshView {
        //获取xib
        let xib = UINib(nibName: "CDRefreshView", bundle: nil)
        //获取视图
        return xib.instantiate(withOwner: nil, options: [:])[0] as! CDRefreshView 
    }
    
}
